/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.great.ad;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.ufc.great.ad.DAO.*;
import br.ufc.great.ad.Model.Evaluation;
import br.ufc.great.ad.Model.Factors;
import br.ufc.great.ad.Model.Level;
import br.ufc.great.ad.Model.Metric;
import br.ufc.great.ad.Model.Parameters;
import br.ufc.great.ad.Model.System;
import java.io.Console;

/**
 *
 * @author great
 */
@Resource
public class EvaluationController {

    private Result result;
    EvaluationDAO EvaluationDAO = new EvaluationDAO();
    Evaluation LastEvaluation;

    public EvaluationController(Result result) {
        this.result = result;
    }

    public void CreateEvaluation() {
        EvaluationDAO.addEvaluation(new Evaluation());
        result.redirectTo("newEvaluation");
    }

    public void newEvaluation() {
    }

    @Post
    public void addSystem(System system) {

        this.LastEvaluation = EvaluationDAO.getLastEvaluation();

        system.setIdEvaluation(LastEvaluation.getIdevaluation());

        EvaluationDAO.addSystem(system);

        result.redirectTo("newEvaluation");

    }

    @Post
    public void addMetric(Metric metric) {

        this.LastEvaluation = EvaluationDAO.getLastEvaluation();

        metric.setIdevaluation(LastEvaluation.getIdevaluation());
        EvaluationDAO.addMetric(metric);
        result.redirectTo("newEvaluation");

    }

    @Post
    public void addParameters(Parameters parameters) {

        this.LastEvaluation = EvaluationDAO.getLastEvaluation();

        parameters.setIdevaluation(LastEvaluation.getIdevaluation());
        EvaluationDAO.addParameters(parameters);
        result.redirectTo("newEvaluation");

    }
@Post
    public void addFactors(Factors factors, Level level1, Level level2, Level level3, Level level4, Level level5) {

        this.LastEvaluation = EvaluationDAO.getLastEvaluation();
        
        
        factors.setIdevaluation(LastEvaluation.getIdevaluation());
        
        Factors factorsSaved = EvaluationDAO.addFactors(factors);
        
        if(!level1.getDescription().equals("")){
        level1.setIdfactors(factorsSaved.getIdfactors());
        EvaluationDAO.addLevel(level1);
        }
        if(!level2.getDescription().equals("")){
        level2.setIdfactors(factorsSaved.getIdfactors());
        EvaluationDAO.addLevel(level2);
        }
        if(!level3.getDescription().equals("")){
        level3.setIdfactors(factorsSaved.getIdfactors());
        EvaluationDAO.addLevel(level3);
        }
        if(!level4.getDescription().equals("")){
        level4.setIdfactors(factorsSaved.getIdfactors());
        EvaluationDAO.addLevel(level4);
        }
        if(!level5.getDescription().equals("")){
        level5.setIdfactors(factorsSaved.getIdfactors());
        EvaluationDAO.addLevel(level5);
        }
        result.redirectTo("newEvaluation");

    }
}
